var a = getApp();

Page({
    data: {
        winWidth: 0,
        winHeight: 0,
        teamId: "",
        logo: "",
        name: "",
        homeImage: "",
        address: "",
        phone: "",
        totalAccessCount: "",
        currentTab: 1,
        pageNo: 1,
        dynamicTotal: -1,
        dynamics: [],
        members: [],
        noworkMembers: [],
        showAllMember: !1,
        date: "",
        time: 1,
        schedules: [],
        shareTitle: "",
        fromShare: !1
    },
    swichNav: function(a) {
        var t = a.target.dataset.current;
        if (this.data.currentTab == t) return !1;
        this.setData({
            currentTab: a.target.dataset.current
        }), 0 == t && -1 == this.data.dynamicTotal && this.loadDynamicData();
    },
    clickMoreMember: function(a) {
        this.setData({
            showAllMember: !0
        });
    },
    clickSchedule: function(t) {
        var e = t.currentTarget.dataset.accesstoken;
        a.util.navToUserHome(e);
    },
    clickCall: function(t) {
        var e = t.currentTarget.dataset.accesstoken;
        a.util.callPhone(e);
    },
    clickShare: function(a) {
        wx.showShareMenu({
            withShareTicket: !1
        });
    },
    clickBack: function(t) {
        var e = a.util.isLogin() ? "/pages/schedule/schedule" : "/pages/hysquare/hysquare";
        wx.reLaunch({
            url: e
        });
    },
    lower: function(a) {
        0 == this.data.currentTab && this.loadDynamicData();
    },
    bindDateChange: function(a) {
        this.setData({
            time: a.detail.timepoint,
            date: a.detail.date
        }), this.loadScheduleData();
    },
    loadHomeData: function() {
        var t = this;
        a.network.post({
            url: a.url.getTeamHomeInfo,
            params: {
                teamId: t.data.teamId
            },
            before: function() {
                wx.showNavigationBarLoading(), t.data.isFirstLoad && wx.showLoading({
                    title: "加载中"
                });
            },
            success: function(e) {
                if (1 == e.data.result) {
                    var i = e.data.data, o = i.weixinProgramShareInfo, n = i.teamInfo;
                    t.setData({
                        logo: n.logo,
                        name: n.name,
                        homeImage: n.homeImage,
                        address: n.address,
                        phone: n.phone,
                        totalAccessCount: n.totalAccessCount,
                        weixinProgramShareInfo: o
                    }), wx.setNavigationBarTitle({
                        title: n.name
                    });
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), t.data.isFirstLoad && (t.setData({
                    isFirstLoad: !1,
                    display: "flex"
                }), wx.hideLoading());
            }
        });
    },
    loadDynamicData: function() {
        var t = this, e = t.data.pageNo;
        t.data.dynamicTotal != t.data.dynamics.length && a.network.post({
            url: a.url.listTeamDynamic,
            params: {
                pageNo: e,
                teamId: this.data.teamId,
                pageSize: 20
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(i) {
                if (1 == i.data.result) {
                    var o = t.data.dynamics;
                    o = o.concat(i.data.data.dynamics), e += 1, t.setData({
                        dynamicTotal: i.data.data.total,
                        dynamics: o,
                        pageNo: e
                    });
                } else a.util.showToast(i.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    loadScheduleData: function() {
        var t = this;
        a.network.post({
            url: a.url.teamTeamSearchScheduleList,
            params: {
                teamId: t.data.teamId,
                scheduleDate: t.data.date,
                time: t.data.time
            },
            before: function() {
                wx.showNavigationBarLoading(), t.data.isFirstLoad && wx.showLoading({
                    title: "加载中"
                });
            },
            success: function(e) {
                if (1 == e.data.result) {
                    var i = e.data.data;
                    t.setData({
                        schedules: i.schedules,
                        shareTitle: i.shareTitle
                    });
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.hideLoading();
            }
        });
    },
    loadTeamHomeData: function() {
        var t = this;
        a.network.post({
            url: a.url.getTeamHomeMember,
            params: {
                teamId: this.data.teamId
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                if (1 == e.data.result) {
                    for (var i = e.data.data.members, o = i.length, n = 0; n < i.length; n++) if ("" == i[n].dynamicType) {
                        o = n;
                        break;
                    }
                    t.setData({
                        members: i.slice(0, o),
                        noworkMembers: i.slice(o, i.length)
                    });
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    onLoad: function(t) {
        var e = this;
        wx.getSystemInfo({
            success: function(a) {
                e.setData({
                    winWidth: a.windowWidth,
                    winHeight: a.windowHeight
                });
            }
        });
        var i = t.teamId, o = !1;
        void 0 != t.fromTo && (o = !0), this.setData({
            teamId: i,
            fromShare: o
        });
        var n = t.date, s = t.time;
        null != n && (this.setData({
            date: n,
            time: s,
            currentTab: 2
        }), this.loadScheduleData()), this.loadHomeData(), this.loadTeamHomeData(), a.util.openSharePage(t);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.weixinProgramShareInfo.shareTitle,
            path: this.data.weixinProgramShareInfo.shareUrl,
            imageUrl: this.data.weixinProgramShareInfo.shareImage,
            success: function(a) {},
            fail: function(a) {}
        };
    }
});